use Flap qw/-m -s/; #no warnings;

sub{
    my $util = shift;
    
    if(ref($_[0]) eq 'HASH'){
        my $h = shift;
        my @q;
        foreach(sort keys %$h){
            $util->uri_escape(\(my $k = $_));
            my $ref = ref $h->{$_};
            if($ref eq 'ARRAY'){
                push(@q, map{ "$k=".$util->uri_escape($_) } @{$h->{$_}});
            }elsif(!$ref){
                push(@q, "$k=".$util->uri_escape($h->{$_}));
            }
        }
        return @q ? join('&', @q) : '';
    }
    
    my $r = ref $_[0] ? shift : do{ \(my $s = shift) };
    $$r =~ s/([\x00-\)+,\/:-?\[-^`\{-\xFF])/$1 eq ' ' ? '+' : '%'.uc(unpack('H*', $1))/eg;
    $$r;
};
